package com.sixth.service.Impl;

import com.sixth.dao.WelcomeDao;
import com.sixth.entity.Dept;
import com.sixth.entity.Goods;
import com.sixth.entity.Staff;
import com.sixth.service.WelcomeService;
import com.sixth.util.LayTab;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * @program: project01
 * @description:
 * @author: 老范
 * @create: 2021-12-27 14:34
 **/
@Service
public class WelcomeServiceImpl implements WelcomeService {
    @Autowired
    private WelcomeDao welcomeDao;
    @Autowired
    private HttpSession session;
    @Override
    public LayTab bing(Dept dept) {
        Staff staff = (Staff) session.getAttribute("staff");
        Integer branchid = staff.getBranchid();
        List<Map> bing = welcomeDao.bing(dept,branchid);
        if(bing.size()>0){
            LayTab layTab = new LayTab(bing.size(),bing);
            return layTab;
        }
        return null;
    }

    @Override
    public LayTab sprice(Goods goods) {
        List<Map> sprice = welcomeDao.sprice(goods);
        if(sprice.size()>0){
            LayTab layTab = new LayTab(sprice.size(), sprice);
            return layTab;
        }
        return null;
    }

    @Override
    public LayTab counts(Goods goods) {
        Staff staff = (Staff) session.getAttribute("staff");
        Integer branchid = staff.getBranchid();
        List<Map> counts = welcomeDao.counts(goods,branchid);

        if (counts.size() > 0) {
            LayTab layTab = new LayTab(counts.size(), counts);
            return layTab;
        }
        return null;
    }

    @Override
    public Integer BranchCount() {
        Integer count = welcomeDao.BranchCount();
        return count;
    }

    @Override
    public Integer StaffCount() {
        Staff staff = (Staff) session.getAttribute("staff");
        Integer branchid = staff.getBranchid();
        Integer count = welcomeDao.StaffCount(branchid);
        return count;
    }

    @Override
    public Integer GoodsCount() {
        Staff staff = (Staff) session.getAttribute("staff");
        Integer branchid = staff.getBranchid();
        Integer count = welcomeDao.GoodsCount(branchid);
        return count;
    }


}
